﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WastedMechanics.CharState
{
    public abstract class CharStateSimpleAction : CharState
    {
        protected float ActionTime;
        protected string AnimationName;       
        bool DidActionPerform;        

        public CharStateSimpleAction(Character chr)
            : base(chr)
        {            
        }

        public override void Enter()
        {
            Character.ResetAnimation(AnimationName);
            Character.SetAnimation(AnimationName);
        }

        public override void Update()
        {
            if (!DidActionPerform && Character.AnimBlender.Target.TimePosition >= Character.AnimBlender.Target.Length * ActionTime)
            {
                ActionPerform();
                DidActionPerform = true;
            }
            else if (Character.AnimBlender.Target.TimePosition >= Character.AnimBlender.Target.Length * 0.99f)
            {
                Character.SwitchState(GetNextState());
            }
        }

        public virtual void ActionPerform() { }

        public abstract CharState GetNextState();

    }
}
